#include<stdio.h>
#include <unistd.h>
#include <sys/stat.h>
#include<fcntl.h>
#include<sys/types.h>
#include<string.h>
#include <sys/stat.h>

int main()
{
 // int fd=open("log.txt",O_WRONLY|O_CREAT,0666);
 // const char* str="hello world!\n";
 // ssize_t n=write(fd,str,strlen(str));
 // if(n<0)
 // {
 //    perror("write");
 // }
 // write(1,str,strlen(str));
  //const char* str="Hello world! You can see me!\n";
  //fprintf(stdout,"hello fprintf\n");
  //write(1,str,strlen(str));
  //fork();
  umask(0); 
  int fd1=open("log_stdout.txt",O_WRONLY|O_CREAT|O_TRUNC,0666);
  int fd2=open("log_stderr.txt",O_WRONLY|O_CREAT|O_TRUNC,0666);
  //int fd2=open("log2.txt",O_WRONLY|O_CREAT|O_TRUNC,0666);
  //int fd3=open("log3.txt",O_WRONLY|O_CREAT|O_TRUNC,0666);
  //int fd4=open("log4.txt",O_WRONLY|O_CREAT|O_TRUNC,0666);
  //int fd5=open("log5.txt",O_WRONLY|O_CREAT|O_TRUNC,0666);
  //int fd6=open("log6.txt",O_WRONLY|O_CREAT|O_TRUNC,0666);
  //int fd7=open("log7.txt",O_WRONLY|O_CREAT|O_TRUNC,0666);

  //printf("%d\n",fd1);
  //printf("%d\n",fd2);
  //printf("%d\n",fd3);
  //printf("%d\n",fd4);
  //printf("%d\n",fd5);
  //printf("%d\n",fd6);
  //printf("%d\n",fd7);
  dup2(fd1,1);
  dup2(fd2,2);
  fprintf(stdout,"stdout\n");
  fprintf(stderr,"stderr\n");

  return 0;
}
